package com.fast.controller.system;

import com.fast.controller.BaseController;
import com.fast.entity.SysRole;
import com.fast.services.SysRoleService;
import com.fast.utils.bean.R;
import com.fast.utils.validator.ValidatorUtils;
import com.fast.utils.validator.group.AddGroup;
import com.fast.utils.validator.group.UpdateGroup;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 角色 管理
 * <p>
 * Created by xiehaitao on 2017/9/9.
 */
@RestController
@RequestMapping("/sys/role")
public class RoleController extends BaseController {


    SysRoleService sysRoleService;


    /**
     * 添加 user
     *
     * @param role
     * @return
     */
    @PostMapping("/adduser")
    public R addRole(SysRole role) {
        ValidatorUtils.validateEntity(role, AddGroup.class);
        role.setCreateTime(new Date());
        sysRoleService.save(role);
        return R.ok();
    }


    /**
     * 修改 角色
     *
     * @param sysRole
     * @return
     */
    @PostMapping("/updateUser")
    public R updateUser(SysRole sysRole) {
        ValidatorUtils.validateEntity(sysRole, UpdateGroup.class);

        sysRoleService.updateSelective(sysRole);

        return R.ok();

    }
}
